package com.efuture.mutlithread;

/**
 * @ClassNAME DaemonThread
 * @Description 守护线程，当用户线程结束，守护线程制动结束
 * @Author zhaoshanshan
 * @Date 2021/9/11 12:41 下午
 * @Version 1.0
 */
public class DaemonThread {

    public static void main(String[] args) {

        DaemonThreadTest t = new DaemonThreadTest();
        t.setName("守护线程");
        t.setDaemon(true);//设置为守护线程
        t.start();
        for(int i=0;i<10;i++){
            System.out.println(Thread.currentThread().getName()+":"+i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }
}
class DaemonThreadTest extends Thread{
    @Override
    public void run() {
        while (true){
            for (int i=0;i<100;i++){
                System.out.println(Thread.currentThread().getName()+":"+i);
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}